package com.example.Utils;


import com.example.model.Admin;
import com.example.model.User;
import com.example.service.impl.UserServiceImpl;
import org.slf4j.Logger;

public class UserHolder {
    private static final ThreadLocal<User> tl = new ThreadLocal<>();
    private static final ThreadLocal<Admin> tl2 = new ThreadLocal<>();
    private static final Logger logger = LoggerUtils.getLogger(UserHolder.class);

    public static void saveUser(User user){
        logger.info("Saving user with openid: {}", user.getWechatOpenid());
        tl.set(user);
    }
    public static void saveAdmin(Admin admin){
        tl2.set(admin);
    }

    public static User getUser(){
        User user = tl.get();
        return user;
    }
    public static Admin getAdmin(){
        Admin admin = tl2.get();
        return admin;
    }
    public static void removeUser(){
        User user = tl.get();
        logger.info("Getting user with openid: {}", user.getWechatOpenid());
        tl.remove();
    }
    public static void removeAdmin(){
        Admin admin = tl2.get();
        tl2.remove();
    }
}
